package com.gupao.service;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import org.springframework.stereotype.Service;

import com.gupao.model.User;

@Service
public class UserService {
	private static Map<Integer, User> database = new HashMap<Integer, User>();
	static {
		User user1 = new User(1, "admin", "admin");
		User user2 = new User(2, "tom", "tom");
		User user3 = new User(3, "mic", "mic");
		database.put(user1.getId(), user1);
		database.put(user2.getId(), user2);
		database.put(user3.getId(), user3);
	}

	public User findUserById(Integer userId) {
		return database.get(userId);
	}

	public User login(String name, String password) {
		for (Entry<Integer, User> entry : database.entrySet()) {
			User user=entry.getValue();
			if(user.getName().equals(name)&&user.getPassword().equals(password)) {
				return user;
			}else {
				continue;
			}
		}
		return null;
	}
}
